package com.crape.account.dao.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.crape.account.dao.IDarrenIndexDAO;
import com.crape.common.exceptions.DAOException;
import com.crape.common.ibatis.SqlMapClientDaoSupportEx;
import com.crape.common.model.AccountInfo;
import com.crape.common.model.DarrenIndex;

public class DarrenIndexDAOImpl extends SqlMapClientDaoSupportEx implements IDarrenIndexDAO {

	@Override
	public DarrenIndex getDarrenIndexBydarrenid(Long darrenid) throws DAOException {
		if(darrenid==null){
			return null;
		}
		return (DarrenIndex) this.queryObject("getDarrenIndexBydarrenid", darrenid);
	}

	@Override
	public void insertDarrenIndex(DarrenIndex darrenIndex) throws DAOException {
		if(darrenIndex==null){
			return;
		}
		this.insert("insertDarrenIndex", darrenIndex);
	}

	@Override
	public void updateDarrenIndex(DarrenIndex darrenIndex) throws DAOException {
		if(darrenIndex==null){
			return;
		}
		this.update("updateDarrenIndex", darrenIndex);
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<AccountInfo> getIndexDarrens(Long accountid, String email, Integer indexType, Integer startIndex, Integer pageSize) throws DAOException {
        if (startIndex == null||pageSize==null||pageSize==0) {
            return null;
        }
        Map<String,Object> params = new HashMap<String,Object>();
        params.put("accountid", accountid);
        params.put("email", email);
        params.put("indexType", indexType);
        params.put("startIndex", startIndex);
        params.put("pageSize", pageSize);
        return (List<AccountInfo>) this.queryList("getIndexDarrens", params);
    }

	@Override
	public Long countIndexDarrens(Long accountid, String email, Integer indexType) throws DAOException {
        Map<String,Object> params = new HashMap<String,Object>();
        params.put("accountid", accountid);
        params.put("email", email);
        params.put("indexType", indexType);
        return (Long) this.queryObject("countIndexDarrens", params);
    }

	@SuppressWarnings("unchecked")
	@Override
	public List<AccountInfo> getIndexShowDarrens(Integer indexType, Integer showNum) throws DAOException {
        if (indexType == null||showNum==null) {
            return null;
        }
        Map<String,Object> params = new HashMap<String,Object>();
        params.put("indexType", indexType);
        params.put("showNum", showNum);
        return (List<AccountInfo>) this.queryList("getIndexShowDarrens", params);
    }

}
